/**
 * @file codeforces/1696/b/main.cpp
 * @brief
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/6/26 20:41:55
 **/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main() {
  // High rating and good luck!
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;
    bool posi = false;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      int x;
      cin >> x;
      if (x && !posi) {
        ans++;
        posi = true;
      }
      if (x == 0) posi = false;
    }
    if (ans > 2) ans = 2;
    cout << ans << endl;
  }
  return 0;
}
